package org.example.service.impl;

import org.example.model.User;
import org.example.service.UserService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {

    // 模拟数据库存储用户（实际项目中替换为数据库查询）
    private static final Map<String, User> userMap = new HashMap<>();

    // 初始化一个测试用户
    static {
        userMap.put("admin", new User("admin", "123456"));
        userMap.put("user", new User("user", "456789"));
    }

    @Override
    public boolean validateUser(String username, String password) {
        User user = userMap.get(username);
        // 验证用户是否存在且密码正确
        return user != null && user.getPassword().equals(password);
    }

    @Override
    public User getUserByUsername(String username) {
        return userMap.get(username);
    }
}
